﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WeatherEvent
{
    class HaveaLoveaAffairExponent : IObserver, IDisplayElement
    {
        private float exponent = 0.0f;
        private WeatherChangeEventArgs _args;
        public HaveaLoveaAffairExponent(WeatherData wd)
        {
            wd.WeatherChange += this.Update;
        }
        public void Display()//输出
        {
            exponent = ComputeHeatIndex(_args.Temperature);
            Console.WriteLine(
                $"HaveaLoveaAffairExponent: " +
                $"\n恋爱指数为：{exponent}");
            Console.WriteLine();       
        }
        public void Update(object sender, WeatherChangeEventArgs args)
        {
            _args = args;
            Display();
        }
        private float ComputeHeatIndex(float t)
        {
            if (t < 1)
            {
                return 10f;
            }
            else if (t < 15 && t >= 1)
            {
                return 30f;
            }
            else if (t < 30 && t >= 15)
            {
                return 100f;
            }
            else if (t >= 30 && t < 45)
            {
                return 60f;
            }
            else
            {
                return 0f;
            }

        }
    }
}
